package com.hp.attendance.serlvet.attendanceManager;

import com.hp.attendance.entity.Employee;
import com.hp.attendance.entity.Overtime;
import com.hp.attendance.entity.PageInfo;
import com.hp.attendance.entity.dto.OvertimeEmpDto;
import com.hp.attendance.service.OvertimeService;
import lombok.Data;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;


@WebServlet("/overtimeMange")
public class overtimePreServlet extends HttpServlet {
    private OvertimeService overtimeService=new OvertimeService();


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pageNo = req.getParameter("pageNo");
        if(pageNo==null ||"".equals(pageNo.trim())) {
            pageNo = "1";
        }
        try {
            PageInfo<OvertimeEmpDto> page = overtimeService.getPage(Integer.parseInt(pageNo), 10);
            req.setAttribute("page",page);
            req.getRequestDispatcher("/pages/overtime_list.jsp").forward(req,resp);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
    }
}
